package com.example.zhihuhelpapp.utils;

import com.example.zhihuhelpapp.bean.QuestionBean;

import org.litepal.crud.DataSupport;

import java.util.List;

public class DbUtils {
    public static List<QuestionBean> getQuestionBean() {
        return DataSupport.order("top desc,updateTime desc")
                .find(QuestionBean.class);
    }

    public static void saveQuestion(QuestionBean questionBean) {
        if (questionBean != null) {
            questionBean.setShowRaking(0);
            questionBean.saveOrUpdate("questionId = ?", questionBean.getQuestionId());
        }
    }

    public static void delQuestion(String questionId) {
        DataSupport.deleteAll(QuestionBean.class, "questionId = ?", questionId);
    }

    public static void delAll(){
        DataSupport.deleteAll(QuestionBean.class);
    }

    public static QuestionBean getQuestion(String questionId) {
        return DataSupport.where("questionId = ?", questionId).findFirst(QuestionBean.class);
    }
}
